<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file="common/head" /}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form action="" id="form" class="layui-form" method="post">
            <input type="hidden" name="id" value="{$info.id|default=0}">

            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>手机号
                </label>
                <div class="layui-input-inline">
                    <input type="number" value="{$info.username}" id="username" name="username" required=""
                           lay-verify="required" autocomplete="off" class="layui-input">

                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>

            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red"></span>头像
                </label>
                <div class="layui-input-inline">
                    <div class="public-img-box">
                        <img src="{$info.user_logo|default='/static/admin/images/img.png'}" id="photo_url" style="width: 120px; height: 120px" alt="">
                    </div>
                    <button type="button" class="layui-btn" id="photo">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <input type="hidden" name="user_logo" id="photo_input" value="{$info.user_logo}">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            {if empty($info['id']) OR $userInfo['id']==1}
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" value="{$info.password}" id="password" name="password" required=""
                           lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>
            {/if}

            <div class="layui-form-item">
                <label for="real_name" class="layui-form-label">
                    <span class="x-red">*</span>真实姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.real_name}" id="real_name" name="real_name" required=""
                           lay-verify="zm" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red"></span>电子邮件
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.email}" id="email" name="email" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            {neq name="info['id']" value="1"}
            <div class="layui-form-item">
                <label for="auth_id" class="layui-form-label">
                    <span class="x-red">*</span>所属角色
                </label>
                <div class="layui-input-inline">
                    <div class="layui-input-inline">
                        <select id="auth_id" name="auth_id" lay-filter="province">
                            <option value="0">还没权限分组角色</option>
                            {volist name='group_list' id='vo'}
                            <option value="{$vo['id']}">{$vo.title}</option>
                            {/volist}
                        </select>

                        <script>$("#auth_id option[value = '{$info.auth_id}']").attr("selected","selected");</script>

                    </div>
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red"></span>状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" {eq name="info['status']" value="1" }checked{/eq}
                    lay-skin="primary" title="正常" checked="">
                    <input type="radio" name="status" value="0" {eq name="info['status']" value="0" }checked{/eq}
                    lay-skin="primary" title="禁用">
                </div>
            </div>
            {/neq}

            <div class="layui-form-item">
                <label for="ok" class="layui-form-label">
                </label>
                <button id="ok" class="layui-btn" lay-filter="add" lay-submit="">
                    {empty name="info['id']"}
                    增 加
                    {else /}
                    修 改
                    {/empty}

                </button>
            </div>
        </form>
    </div>
</div>

<div id="idbox" style="display: none">

</div>
<script>layui.use(['form', 'layer'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            zm: function (value) {
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '真实姓名不能有特殊字符';
                }
            }
        });

        //监听提交
        form.on('submit(add)',
            function (data) {
                $.ajax({
                    type: "POST",
                    url: "{:url()}",
                    data: data.field,
                    success: function (result) {
                        if(result.code){
                            layer.alert(result.msg, {
                                icon: 6
                            }, function () {
                                xadmin.close();
                                xadmin.father_reload();
                            });
                        }else{
                            layer.alert(result.msg,{
                                icon: 2
                            });
                        }
                    },
                    error: function (result) {
                        layer.alert(result.msg, {
                            icon: 2
                        }, function () {
                            xadmin.close();
                        });
                    }

                });
                return false;
            });

        layui.use('upload', function(){
            var upload = layui.upload;

            //执行实例
            var uploadInst = upload.render({
                elem: '#photo' //绑定元素
                ,url: '{:url("File/upload")}' //上传接口
                ,accept: 'images' //只允许上传图片
                ,acceptMime: 'image/*' //只筛选图片
                ,before: function(obj){
                    layer.load();
                }
                ,done: function(res){
                    if(res.code){
                        $("#photo_url").attr("src",res.data.url);
                        $("#photo_input").val(res.data.url);
                    }else{
                        layer.msg(res.msg,{icon:2,time:1000});
                    }
                    layer.closeAll('loading');
                }
                ,error: function(res){
                    //请求异常回调
                    layer.closeAll('loading');
                }
            });
        });


    });
</script>

</body>

</html>
